package gui;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import Controlador.Controlador;
import Controlador.ControladorItem;
import beans.ItemLista;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class GananciaFrame extends Vista {

	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	private JFrame ventana = new JFrame();
	
	

	public static void main(String[] args) {
		GananciaFrame GF = new GananciaFrame();
		Controlador Ganancia= new ControladorItem(GF);
		GF.addcontroladorItem(Ganancia);
		
	} 
	

	public GananciaFrame()
	{
		super();
		initGUI();
	}
	
	
	private void initGUI() {
		try {
			setVentana(ventana);
			
			
			
			
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	
	private void borrarTextos() {
		iditem.setText("");
		porcentaje.setText("");
		
	}
	
	private void jButtonaceptarActionPerformed(ActionEvent evt) {

		if (iditem.getText().length()==0 || porcentaje.getText().length()==0){
			System.out.println("Debe completar los campos");
		}
		
		ItemLista IL =((ControladorItem)getControladorItem()).buscarItem(Long.parseLong(iditem.getText()));
	
		if (IL!=null) {
			((ControladorItem)getControladorItem()).modificarItem(IL,Float.parseFloat(porcentaje.getText()));
			borrarTextos();		
			}
		else
			{
				System.out.println("Id Inexistente");
			}
		}

	
	private JPanel jPanel1;
	private JTextField iditem;
	private JTextField porcentaje;
	private JLabel txganancia;
	private JButton jButtoncancelar;
	private JButton jButtonaceptar;
	private JLabel txtid;



	public JFrame getVentana() {
		return ventana;
	}


	public void setVentana(JFrame ventana) {
		this.ventana = ventana;
		{
			jPanel1 = new JPanel();
			ventana.getContentPane().add(jPanel1, BorderLayout.CENTER);
			jPanel1.setLayout(null);
			jPanel1.setPreferredSize(new java.awt.Dimension(399, 277));
			ventana.setTitle("Establecer % de Ganancia");
			{
				txtid = new JLabel();
				jPanel1.add(txtid);
				txtid.setText("IdItem");
				txtid.setBounds(12, 22, 87, 16);
			}
			{
				jButtonaceptar = new JButton();
				jPanel1.add(jButtonaceptar);
				jButtonaceptar.setText("Aceptar");
				jButtonaceptar.setBounds(41, 235, 88, 23);
				jButtonaceptar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						jButtonaceptarActionPerformed(evt);
					}
				});
			}
			{
				jButtoncancelar = new JButton();
				jPanel1.add(jButtoncancelar);
				jButtoncancelar.setText("Cancelar");
				jButtoncancelar.setBounds(211, 231, 95, 23);
				jButtoncancelar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						jButtoncancelarActionPerformed(evt);
					}
				});
			}
			{
				iditem = new JTextField();
				jPanel1.add(iditem);
				iditem.setBounds(197, 19, 109, 23);
			}
			{
				porcentaje = new JTextField();
				jPanel1.add(porcentaje);
				porcentaje.setBounds(197, 59, 109, 23);
			}
			{
				txganancia = new JLabel();
				jPanel1.add(txganancia);
				txganancia.setText("Porcentaje Ganancia");
				txganancia.setBounds(12, 66, 134, 16);
			}
			ventana.setLocationRelativeTo(null);
			ventana.setVisible(true);
			ventana.pack();
		}
	}
	
	private void jButtoncancelarActionPerformed(ActionEvent evt) {
		this.ventana.dispose();
	}

}
